
Page({
  data: {
    page: 1,
    maxPage: 10,
    totalPages: 1,
    showbottom: false,
    bottomtext: '正在加载..',
    recordlist: [],
    chaojishow:false,
    chaoji: getApp().globalData.source + "dialog/chaoji.png",
  },

  closePopUp:function(){
    var that = this;
    this.setData({
      chaojishow: !that.data.chaojishow
    })
  },
  onLoad: function (options) {
      this.getdata();
  },
  getdata: function () {
    var vm = this
    var userIds = wx.getStorageSync("userId") === "" ? -1 : wx.getStorageSync("userId");
    var data = {
      userId: userIds,
      startPoint: vm.data.page,
      maxPage: vm.data.maxPage
    }
    getApp().requestLoading(getApp().globalData.https + "orderResource/pkgRecord/" + userIds+"/0",
      "get", data,"加载中..",
      function (res) {
        wx.stopPullDownRefresh()
        if (res.code == 0) {

          // <!--交易类型 0.充值，1.购买，2.提现，3.签到，4.助力，5.听时长，6.随机活动，7.邀请好友-- >
          var newdata = [];
          vm.setData({
            recordlist: vm.data.recordlist.concat(res.data.data),
            totalPages: res.data.totalPages
          })
          if (res.data.data.length < 10) {
            vm.setData({
              bottomtext: "已加载全部数据",
              showbottom: true
            })
          }
          //如果返回数据小于设定的每页个数就显示底部
          if (newdata.length < 10) {
            vm.setData({
              showbottom: true
            })
          }
        }
      },
      function (res) { });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      recordlist:[]
    })
    this.getdata()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.page < that.data.totalPages) {
      that.setData({
        page: that.data.page + 1
      })
      this.getdata()
    } else {
      that.setData({
        showbottom: true,
        bottomtext: "已加载全部数据",
      })
    }
  },
})